//
//  ILSettingViewController.m
//  Lottery
//
//  Created by app43 on 15/7/9.
//  Copyright (c) 2015年 app43. All rights reserved.
//

#import "ILSettingViewController.h"
#import "ILPushNoticeViewController.h"
//#import "ILShareViewController.h"
#import "ILAboutViewController.h"
#import "ILHelpViewController.h"
#import "ILProductsViewController.h"
#import "UMSocial.h"


#import "ILAppInfo.h"
@interface ILSettingViewController () <UIAlertViewDelegate>
@end

@implementation ILSettingViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 1.第0组：3个
    [self add0SectionItems];
    
    // 2.第1组：6个
    [self add1SectionItems];
}

#pragma mark 添加第0组的模型数据
- (void)add0SectionItems
{
    // 1.1.推送和提醒
    ILSettingArrowItem *push = [ILSettingArrowItem itemWithIcon:@"MorePush" title:@"推送和提醒"];
    push.showVCClass = [ILPushNoticeViewController class];
    // copy状态下的block（堆里面的block）会对里面所使用的外界变量 产生 强引用
    //    __weak ILSettingViewController *setting = self;
    //    push.operation = ^{
    //        ILPushNoticeViewController *notice = [[ILPushNoticeViewController alloc] init];
    //        [setting.navigationController pushViewController:notice animated:YES];
    //    };
    
    // 1.2.摇一摇机选
    ILSettingSwitchItem *shake = [ILSettingSwitchItem itemWithIcon:@"handShake" title:@"摇一摇机选"];
    shake.key = ILSettingShakeChoose;
    
    // 1.3.声音效果
    ILSettingSwitchItem *sound = [ILSettingSwitchItem itemWithIcon:@"sound_Effect" title:@"声音效果"];
    sound.key = ILSettingSoundEffect;
    
    ILSettingGroup *group = [[ILSettingGroup alloc] init];
    group.items = @[push, shake, sound];
    [_allGroups addObject:group];
}
-(NSInteger)back{
    return 1;
}
int p  = 3;
#pragma mark 添加第1组的模型数据
- (void)add1SectionItems
{
//    // 2.1.检查新版本
//    ILSettingArrowItem *update = [ILSettingArrowItem itemWithIcon:@"MoreUpdate" title:@"检查新版本"];
//    update.operation = ^{
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"目前已是最新版本了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//        [alert show];



    
    
//    // 2.1.检查新版本
//    NSString *path=[[NSBundle mainBundle]pathForResource:@"Info.plist" ofType:nil];
//    NSDictionary *dic=[NSDictionary dictionaryWithContentsOfFile:path];
//    int index=[dic[@"Bundle version"] integerValue];
//    NSLog(@"%d",index);
//    int i=0;
//
    
   
    ILSettingArrowItem *update = [ILSettingArrowItem itemWithIcon:@"MoreUpdate" title:@"检查新版本"];
    __unsafe_unretained ILSettingViewController *setting = self;
    NSInteger a = [self back];
    if(p > a)
    {
    update.operation = ^{
        
        //        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"目前已是最新版本了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        //        [alert show];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"检测到新版本" message:@"版本新特性如下：\n1.修正了少数BUG\n2.增加了什么模块\n3.增强了用户体验" delegate:setting cancelButtonTitle:@"取消" otherButtonTitles:@"前往下载", nil];
        [alert show];
    };
    }
   else
    
        {
            
            update.operation = ^{
                
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"目前已是最新版本了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                        [alert show];
//
//                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"检测到新版本" message:@"版本新特性如下：\n1.修正了少数BUG\n2.增加了什么模块\n3.增强了用户体验" delegate:setting cancelButtonTitle:@"取消" otherButtonTitles:@"前往下载", nil];
//                [alert show];
            };
        }
    
    
    // 2.2.帮助
    ILSettingArrowItem *help = [ILSettingArrowItem itemWithIcon:@"MoreHelp" title:@"帮助"];
    help.showVCClass = [ILHelpViewController class];
    
    // 2.3.分享
    ILSettingArrowItem *share = [ILSettingArrowItem itemWithIcon:@"MoreShare" title:@"分享"];
    share.operation=^{
        //友盟分享
        
            //注意：分享到微信好友、微信朋友圈、微信收藏、QQ空间、QQ好友、来往好友、来往朋友圈、易信好友、易信朋友圈、Facebook、Twitter、Instagram等平台需要参考各自的集成方法
            /* 参数含义
             SheetView: 需要在哪个视图中展示
             appKey: 当前应用的友盟分享的key
             shareText: 需要分享的文本
             shareImage: 需要分享的图片
             shareToSnsNames: 需要分享到的平台
             */
            /*
             [UMSocialSnsService presentSnsIconSheetView:self
             appKey:@"5458264dfd98c5b5c9007064"
             shareText:@"你要分享的文字"
             shareImage:[UIImage imageNamed:@"icon.png"]
             shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren, UMShareToDouban, UMShareToFacebook, UMShareToFlickr, UMShareToInstagram, nil]
             delegate:nil];
             */
            
            [UMSocialSnsService presentSnsIconSheetView:self
                                                 appKey:@"559f858667e58ed9c4005c91"
                                              shareText:@"友盟社会化分享让您快速实现分享等社会化功能，www.umeng.com/social"
                                             shareImage:[UIImage imageNamed:@"icon.png"]
                                        shareToSnsNames:@[UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToQzone]
                                               delegate:self];
      
};
    //share.showVCClass = [ILShareViewController class];
    
//    // 2.4.查看消息
//    ILSettingArrowItem *msg = [ILSettingArrowItem itemWithIcon:@"MoreMessage" title:@"查看消息"];
    
    
    
    
    
    
    // 2.4.查看消息
    ILSettingArrowItem *msg = [ILSettingArrowItem itemWithIcon:@"MoreMessage" title:@"查看消息"];
    msg.operation = ^{
        UIApplication *app = [UIApplication sharedApplication];
        [app openURL:[NSURL URLWithString:@"skapp://cn.sk.mjapp"]];
        
        
        UIApplication *app1 = [UIApplication sharedApplication];
        [app1 openURL:[NSURL URLWithString:@"sina://cn.view.weibo"]];
    };
    
    
    // 2.5.产品推荐
    ILSettingArrowItem *product = [ILSettingArrowItem itemWithIcon:@"MoreNetease" title:@"产品推荐"];
    product.showVCClass = [ILProductsViewController class];
    
    // 2.6.关于
    ILSettingArrowItem *about = [ILSettingArrowItem itemWithIcon:@"MoreAbout" title:@"关于"];
    about.showVCClass = [ILAboutViewController class];
    
    ILSettingGroup *group = [[ILSettingGroup alloc] init];
    group.items = @[update, help, share, msg, product, about];
    [_allGroups addObject:group];
}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        UIApplication *app = [UIApplication sharedApplication];
        NSString *urlStr = [NSString stringWithFormat:@"http://itunes.apple.com/app/id%@?mt=8", ILAppId];
        NSURL *url = [NSURL URLWithString:urlStr];
        if ([app canOpenURL:url]) {
            [app openURL:url];
        }
    }
}



@end
